/**
 * @author 杜猛
 * @created 2020/03/12
 * @describe 整体路由json aes加密  传入原始数据  return 加密/解密值
 */
import CryptoJS from '@/utils/aes.js'
// 加密
CryptoJS.$aesMenuJiaMi = (encrypted) => {
  if (encrypted) {
    var key = CryptoJS.enc.Hex.parse('42accba6c2454c238c04deddeb984493')
    var iv = CryptoJS.enc.Hex.parse('9641b65a34d74bbda74e5ec3eab394b3')
    var string = encrypted
    var data = CryptoJS.AES.encrypt(string, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    })
    var uncrypted = data.toString()
    return uncrypted
  }
}
//   解密
CryptoJS.$aesMenuJieMi = (encrypted) => {
  if (encrypted) {
    var key = CryptoJS.enc.Hex.parse('42accba6c2454c238c04deddeb984493')
    var iv = CryptoJS.enc.Hex.parse('9641b65a34d74bbda74e5ec3eab394b3')
    var string = encrypted
    var uncrypted = ''
    try {
      var data = CryptoJS.AES.decrypt(string, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
      })
      uncrypted = data.toString(CryptoJS.enc.Utf8)
    } catch (e) {
      uncrypted = encrypted
    }
    return uncrypted
  }
}
export default CryptoJS
